package com.windowes.weichang.controller.manage;

import com.windowes.weichang.access.AccessLimit;
import com.windowes.weichang.common.ServerResponse;
import com.windowes.weichang.dto.ShopDto;
import com.windowes.weichang.dto.WidthdrawApplyDTO;
import com.windowes.weichang.pojo.WShop;
import com.windowes.weichang.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/***
 *
 * @author: yangqing
 * @email: qing.yang@bangdao-tech.com
 * @createTime: 2018/5/28 上午7:42
 * @description:
 *
 **/
@RestController
@Api(description = "店铺相关API")
@RequestMapping("shop")
public class ShopController {

    @Autowired
    ShopService shopService;

    @ApiOperation(value = "获取店铺列表", notes = "")
    @GetMapping("list")
    public ServerResponse list(String keyword, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                               @RequestParam(value = "pageSize", defaultValue = "15") int pageSize) {
        return shopService.list(keyword, pageNo, pageSize);
    }


    @ApiOperation(value = "获取单个店铺", notes = "")
    @GetMapping("item")
    public ServerResponse item(Integer id) {
        return shopService.item(id);
    }

    @AccessLimit(manageUser = true)
    @ApiOperation(value = "添加店铺", notes = "")
    @PostMapping("saveOrUpdate")
    public ServerResponse add(@RequestBody ShopDto shop) {
        return shopService.add(shop);
    }


    @ApiOperation(value = "删除店铺", notes = "")
    @PostMapping("delete")
    public ServerResponse delete(Integer id) {
        return shopService.delete(id);
    }


    @ApiOperation(value = "同步地区数据至百度地图", notes = "内部接口请勿调用")
    @GetMapping("ds_shop")
    public ServerResponse dataSynchronized() {
        return shopService.dataSynchronized();
    }


    @ApiOperation(value = "搜索附近店铺", notes = "")
    @GetMapping("search")
    public ServerResponse search(BigDecimal longtitude, BigDecimal latitude, String q, @RequestParam(name = "radius", defaultValue = "50000") long radius) {
        return shopService.search(longtitude, latitude, q, radius);
    }

    @ApiOperation(value = "提交店铺申请", notes = "【商家】")
    @AccessLimit
    @PostMapping("apply")
    public ServerResponse apply(@RequestBody WShop applyInfoDto) {
        return shopService.apply(applyInfoDto);
    }

    @ApiOperation(value = "店铺审核通过", notes = "【平台】")
    @AccessLimit
    @PostMapping("approve")
    public ServerResponse approve(Integer id) {
        return shopService.approve(id);
    }

    @ApiOperation(value = "店铺审核拒绝", notes = "【平台】")
    @AccessLimit
    @PostMapping("refuse")
    public ServerResponse refuse(Integer id, String reason) {
        return shopService.refuse(id, reason);
    }


    @ApiOperation(value = "店铺等待审核列表", notes = "【平台】")
    @GetMapping("apply")
    public ServerResponse waitting(String keyword, @RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                   @RequestParam(value = "pageSize", defaultValue = "15") int pageSize, @RequestParam(value = "applyState", defaultValue = "P") String applyState) {
        return shopService.waittingList(keyword, pageNo, pageSize, applyState);
    }

    @AccessLimit(shopUser = true)
    @ApiOperation(value = "获取钱包信息", notes = "店铺")
    @GetMapping("wallet")
    public ServerResponse wallet() {
        return shopService.wallet();
    }

    @AccessLimit(shopUser = true)
    @ApiOperation(value = "获取钱包信息", notes = "店铺")
    @GetMapping("withdrawList")
    public ServerResponse withdrawList(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                       @RequestParam(value = "pageSize", defaultValue = "15") int pageSize) {
        return shopService.withdrawList(pageNo, pageSize);
    }

    @AccessLimit(manageUser = true)
    @ApiOperation(value = "获取取款列表", notes = "店铺")
    @GetMapping("withdrawApplyList")
    public ServerResponse withdrawApplyList(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                            @RequestParam(value = "pageSize", defaultValue = "15") int pageSize) {
        return shopService.withdrawApplyList(pageNo, pageSize);
    }

    @AccessLimit
    @ApiOperation(value = "提交申请", notes = "店铺")
    @PostMapping("submitWithdraw")
    public ServerResponse submitWithdraw(@RequestBody WidthdrawApplyDTO widthdrawApplyDTO) {
        return shopService.submitWithdraw(widthdrawApplyDTO);
    }

    @AccessLimit
    @ApiOperation(value = "同意提现", notes = "平台")
    @PostMapping("approveWithdraw")
    public ServerResponse approveWithdraw(Integer applyId) {
        return shopService.approveWithdraw(applyId);
    }


}
